<?php

/**
 * Controller_prizelv
 */

class Controller_prizelv extends MyApp {


    /** 首页 **/
    public function actionIndex()
    {

        $this->tpl->display();
    }
    /** ---------------------------------部门设置---------------------------------------- **/
    /** 部门列表 **/
    public function actionPrizelvList()
    {
        // 分页
        YOU::loadLib('page', "", '0');

        $tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_prizelv`");
        $count = $tmp['count'];
        $page_total = ceil($count/PAGE_LIMIT);

        // 当前页
        $p = intval($_GET['p']);
        if ($p == 0){
            $p  = 1;
        }
        if ($p > 1){
            $start = PAGE_LIMIT * ($p-1);
        }else{
            $start = 0;
        }

        $prizelv_lists = $this->db->fetchAll("SELECT * FROM `tbl_prizelv` ORDER BY prizelv_id DESC LIMIT {$start}, ".PAGE_LIMIT."");

        $page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
        $page->next_page   = '下一页>';
        $page->pre_page    = '<上一页';
        $page->style_path  = "static/page_style";

        $this->tpl->assign("page", $page->show(4, "yahoo"));
        $this->tpl->assign("prizelv_lists", $prizelv_lists);
        $this->tpl->display('prizelv/prizelv.list.tpl.php');
    }
    /** 部门添加 **/
    public function actionPrizelvAdd()
    {
        if ($_POST){

            $prizelv_name     	= $this->post->prizelv_name;

            // 写入数据库
            $info = array(

                "prizelv_name"      	=> $prizelv_name,
                "status"                => 1,
                "create_time"           => date("Y-m-d H:i:s"),
                "update_time"           => "0000-00-00 00:00:00",

            );
            $this->db->do_insert("tbl_prizelv", $info);

            // 跳转
            Helper_Client::location("添加成功", "index.php?a=prizelv.prizelvlist");
        }

        $this->tpl->display('prizelv/prizelv.add.tpl.php');
    }
    /** 部门修改 **/
    public function actionPrizelvUpdate()
    {

        $prizelv_id   = (int)$this->get->prizelv_id;
        $prizelv_data = $this->db->fetchRow("SELECT * FROM `tbl_prizelv` WHERE `prizelv_id`='{$prizelv_id}'");

        if (empty($prizelv_data)){
            Helper_Client::alert("该奖名称不存在");
        }

        if ($_POST){

            $prizelv_name        = $this->post->prizelv_name;

            // 写入数据库
            $info = array(

                "prizelv_name"     	=> $prizelv_name,
                "status"                => 1,
                "create_time"           => date("Y-m-d H:i:s"),
                "update_time"           => "0000-00-00 00:00:00",
            );
            $this->db->do_update("tbl_prizelv", $info, "prizelv_id='{$prizelv_id}'");

            // 跳转
            Helper_Client::location("修改成功", "index.php?a=prizelv.prizelvlist");
        }

        $this->tpl->assign("prizelv_data", $prizelv_data);
        $this->tpl->display('prizelv/prizelv.update.tpl.php');
    }
    /** 部门删除 **/
    public function actionPrizelvDel()
    {
        $prizelv_id = $this->get->prizelv_id;
        $this->db->query("DELETE  FROM `tbl_prizelv` WHERE prizelv_id='{$prizelv_id}'");

        // 跳转
        Helper_Client::location("删除成功", "index.php?a=prizelv.prizelvlist");
    }
    /** -------------------------------- 上级部门设置部门 ------------------------------- **/
    /** 上级部门列表 **/
    public function actionUpPrizelvList()
    {
        // 分页
        YOU::loadLib('page', "", '0');

        $tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_prizelv_up`");
        $count = $tmp['count'];
        $page_total = ceil($count/PAGE_LIMIT);

        // 当前页
        $p = intval($_GET['p']);
        if ($p == 0){
            $p  = 1;
        }
        if ($p > 1){
            $start = PAGE_LIMIT * ($p-1);
        }else{
            $start = 0;
        }

        $up_lists = $this->db->fetchAll("SELECT * FROM `tbl_prizelv_up` ORDER BY up_id DESC LIMIT {$start}, ".PAGE_LIMIT."");

        $page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
        $page->next_page   = '下一页>';
        $page->pre_page    = '<上一页';
        $page->style_path  = "static/page_style";

        $this->tpl->assign("page", $page->show(4, "yahoo"));
        $this->tpl->assign("up_lists", $up_lists);
        $this->tpl->display('prizelv/prizelv.up.list.tpl.php');
    }
    /** 上级部门添加 **/
    public function actionUpPrizelvAdd()
    {
        if ($_POST){

            $up_name     	= $this->post->up_name;

            // 写入数据库
            $info = array(

                "up_name"      			=> $up_name,
                "status"                => 1,
                "create_time"           => date("Y-m-d H:i:s"),
                "update_time"           => "0000-00-00 00:00:00",

            );
            $this->db->do_insert("tbl_prizelv_up", $info);

            // 跳转
            Helper_Client::location("添加成功", "index.php?a=prizelv.upprizelvlist");
        }

        $this->tpl->display('prizelv/prizelv.up.add.tpl.php');
    }
    /** 上级部门修改 **/
    public function actionUpPrizelvUpdate()
    {

        $up_id   		 = (int)$this->get->up_id;
        $up_data = $this->db->fetchRow("SELECT * FROM `tbl_prizelv_up` WHERE `up_id`='{$up_id}'");

        if (empty($up_data)){
            Helper_Client::alert("该奖不存在");
        }

        if ($_POST){

            $up_name        		= $this->post->up_name;

            // 写入数据库
            $info = array(

                "up_name"     			=> $up_name,
                "status"                => 1,
                "create_time"           => date("Y-m-d H:i:s"),
                "update_time"           => "0000-00-00 00:00:00",
            );
            $this->db->do_update("tbl_prizelv_up", $info, "up_id='{$up_id}'");

            // 跳转
            Helper_Client::location("修改成功", "index.php?a=prizelv.upprizelvlist");
        }

        $this->tpl->assign("up_data", $up_data);
        $this->tpl->display('prizelv/prizelv.up.update.tpl.php');
    }
    /** 上级部门删除 **/
    public function actionUpPrizelvDel()
    {
        $up_id = $this->get->up_id;
        $this->db->query("DELETE  FROM `tbl_prizelv_up` WHERE up_id='{$up_id}'");

        // 跳转
        Helper_Client::location("删除成功", "index.php?a=prizelv.upprizelvlist");
    }


}

?>